<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑学生信息</title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
    <link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link href="css/admin.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery.js"></script>
    <style>
        .forminfo li {
            margin-bottom: 15px;
            position: relative;
        }
        .forminfo label {
            width: 100px;
            text-align: right;
            padding-right: 10px;
            font-weight: 500;
            color: #646464;
        }
        .forminfo .dfinput {
            width: 345px;
            border: 1px solid #d7d7d7;
            height: 32px;
            padding-left: 10px;
            border-radius: 3px;
        }
        .forminfo .dfinput:focus {
            border-color: #66afe9;
            outline: 0;
            box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
        }
        .gender-options {
            display: inline-block;
            line-height: 32px;
        }
        .gender-label {
            width: auto !important;
            margin-right: 15px;
            font-weight: normal !important;
        }
        .btn {
            padding: 6px 20px;
            margin-right: 10px;
        }
        .btn-primary {
            color: #fff;
            background-color: #337ab7;
            border-color: #2e6da4;
        }
        .btn-primary:hover {
            background-color: #286090;
            border-color: #204d74;
        }
        .formtitle {
            border-bottom: 1px solid #d7d7d7;
            margin-bottom: 20px;
            padding-bottom: 5px;
        }
        .formtitle span {
            font-size: 16px;
            font-weight: bold;
            color: #337ab7;
        }
        .required-mark {
            color: red;
            margin-left: 3px;
            font-weight: bold;
        }
    </style>
</head>

<body>
<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="admin_index.html">首页</a></li>
        <li><a href="admin_student_list.html">学生管理</a></li>
        <li><a href="#">编辑学生</a></li>
    </ul>
</div>

<div class="formbody">
    <div class="formtitle"><span>学生信息</span></div>
    
    <form id="studentForm">
        <input type="hidden" id="studentId" name="studentId">
        <ul class="forminfo">
            <li>
                <label>学号<span class="required-mark">*</span></label>
                <input name="studentNo" type="text" class="dfinput" placeholder="请输入学号"/>
            </li>
            <li>
                <label>姓名<span class="required-mark">*</span></label>
                <input name="studentName" type="text" class="dfinput" placeholder="请输入姓名"/>
            </li>
            <li>
                <label>性别<span class="required-mark">*</span></label>
                <div class="gender-options">
                    <input name="gender" type="radio" value="男" id="male"/><label for="male" class="gender-label">男</label>
                    <input name="gender" type="radio" value="女" id="female"/><label for="female" class="gender-label">女</label>
                </div>
            </li>
            <li>
                <label>学院<span class="required-mark">*</span></label>
                <input name="college" type="text" class="dfinput" placeholder="请输入学院名称"/>
            </li>
            <li>
                <label>专业<span class="required-mark">*</span></label>
                <input name="major" type="text" class="dfinput" placeholder="请输入专业名称"/>
            </li>
            <li>
                <label>班级<span class="required-mark">*</span></label>
                <input name="className" type="text" class="dfinput" placeholder="请输入班级名称"/>
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="button" class="btn btn-primary" value="保存" onclick="updateStudent()"/>
                <input type="button" class="btn" value="返回" onclick="history.back()"/>
            </li>
        </ul>
    </form>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        // 获取URL参数
        var getUrlParam = function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURIComponent(r[2]); return null;
        };
        
        // 获取学生ID
        var id = getUrlParam('id');
        if (!id) {
            alert("未指定学生ID");
            window.location.href = "admin_student_list.html";
            return;
        }
        
        // 模拟从后端获取学生数据
        var student = {
            id: id,
            studentNo: "2023" + id,
            studentName: "学生" + id,
            gender: id % 2 === 0 ? "女" : "男",
            college: "计算机学院",
            major: "软件工程",
            className: "软工2班"
        };
        
        // 填充表单
        $("#studentId").val(student.id);
        $("input[name='studentNo']").val(student.studentNo);
        $("input[name='studentName']").val(student.studentName);
        $("input[name='gender'][value='" + student.gender + "']").prop("checked", true);
        $("input[name='college']").val(student.college);
        $("input[name='major']").val(student.major);
        $("input[name='className']").val(student.className);
    });
    
    function updateStudent() {
        // 获取表单数据
        var studentId = $("#studentId").val();
        var studentNo = $("input[name='studentNo']").val();
        var studentName = $("input[name='studentName']").val();
        var gender = $("input[name='gender']:checked").val();
        var college = $("input[name='college']").val();
        var major = $("input[name='major']").val();
        var className = $("input[name='className']").val();
        
        // 基本验证
        if (studentNo == "") {
            alert("请输入学号！");
            return;
        }
        if (studentName == "") {
            alert("请输入姓名！");
            return;
        }
        if (!gender) {
            alert("请选择性别！");
            return;
        }
        if (college == "") {
            alert("请输入学院名称！");
            return;
        }
        if (major == "") {
            alert("请输入专业名称！");
            return;
        }
        if (className == "") {
            alert("请输入班级名称！");
            return;
        }
        
        // 构建学生对象
        var student = {
            id: studentId,
            studentNo: studentNo,
            studentName: studentName,
            gender: gender,
            college: college,
            major: major,
            className: className
        };
        
        // 模拟后端更新操作
        alert("学生信息更新成功！");
        
        // 返回列表页
        window.location.href = "admin_student_list.html";
    }
</script>
</body>
</html> 